package com.vincce.sport.core.utils;

import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.imageio.ImageIO;

import com.vincce.sport.entity.PlayerCreateImg;
import com.vincce.sport.entity.TeamCreateImg;

/**
 * Created by xupeng on 14-10-18.
 */
public class imageUtil {
    public static <T> InputStream  BuildPlayer(String background,TeamCreateImg teamdate
    ) throws IOException {
    		ArrayList<PlayerCreateImg> list=(ArrayList<PlayerCreateImg>) teamdate.getList();
    		Date date=new Date();
    		String imagefilename;
    		SimpleDateFormat formatter=new SimpleDateFormat("yyyyHHddHHmmss");  
    		String time=formatter.format(date);
    		String imagefilesname="/data/tomcat-file/file/webapps/images/";
    		File files =new File(imagefilesname);    
    		//如果文件夹不存在则创建    
    		if(!files.exists()&&!files.isDirectory())      
    		{       
    			files.mkdir();
    			imagefilename=imagefilesname+"/"+time+".png";
    			File file=new File(imagefilename); 
    			//如果文件不存在则创建
    				if(!file.exists())    
    				{    
    					try {    
    							file.createNewFile();    
    						} catch (IOException e) {    
    							e.printStackTrace();    
    						}    
    				} 
    		} else   
    		{ 
    			 imagefilename=imagefilesname+"/"+time+".png";
    			File file=new File(imagefilename); 
    			//如果文件不存在则创建
    				if(!file.exists())    
    				{    
    					try {    
    							file.createNewFile();    
    						} catch (IOException e) {    
    							e.printStackTrace();    
    						}    
    				} 
             
    		}  
       
        String logurl=teamdate.getLogUrl();
        String cu="http://images.cu-league.com";
        String imagelefturl = cu+logurl.replaceFirst("%s","ori");

        // 创建绘制图片
        BufferedImage image;
        // 获得绘制图片url
        URL url = new URL(background);
        // 打开URL对应的资源的输入流
        InputStream backgroundurl = url.openStream();
        // 从网络中读取图片
        image = ImageIO.read(backgroundurl);
        // 获得绘制图片中的左球队队标
        URL urlleft = new URL(imagelefturl);
        // 打开URL对应的资源的输入流
        InputStream imageleft = urlleft.openStream();
        // 从网络中添加图片
        BufferedImage bufferedImageLeft = ImageIO.read(imageleft);
        // 获取图形上下文
        Graphics2D graphics = (Graphics2D) image.getGraphics();
        AlphaComposite composite=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.3f);
        graphics.setComposite(composite);
        graphics.drawImage(bufferedImageLeft, 300, 180, 230, 230, null);
        graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.3f));
        graphics.setComposite(composite);
        graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        // 消除线条锯齿
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        RenderingHints rh = new RenderingHints(
                RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        rh.put(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        graphics.setRenderingHints(rh); // 设置图片质量

        graphics.setStroke(new BasicStroke(3)); // 设置线的粗细
        // 图1标题
        String text = "2014-2015 U-LEAGUE";
        Font font = new Font("方正超粗黑", Font.LAYOUT_RIGHT_TO_LEFT, 18);
        FontRenderContext frc = graphics.getFontRenderContext();
        TextLayout tl = new TextLayout(text, font, frc);
        tl.draw(graphics, 307, 35);
        graphics.setColor(Color.white);
        graphics.setStroke(new BasicStroke(1)); // 设置线的粗细
        int x = 50, y = 135, x3 = 700, y3 = y;
        graphics.drawLine(x, y, x + x3, y3);

        // 设置文字内容、位置
        graphics.setFont(new Font("方正黑体", Font.BOLD, 15));
        
        graphics.drawString("", 100, 30);
        graphics.drawString("", 695, 30);
        graphics.drawString(teamdate.getTotalScore().toString(), 255, 80);
        graphics.drawString(teamdate.getOpponentTotalScore().toString(), 535, 80);

        graphics.setFont(new Font("方正黑体", Font.BOLD, 11));
        graphics.drawString("球队", 325, 69);
		graphics.drawString("1st", 360, 69);
		graphics.drawString("2st", 381, 69);
		graphics.drawString("3st", 405, 69);
		graphics.drawString("4st", 428, 69);
		graphics.drawString("全场 ", 454, 69);
		graphics.drawString("主", 327, 84);
		graphics.drawString("客", 327, 97);
        graphics.drawString(teamdate.getFirstSectionScore().toString(), 362, 84);
        graphics.drawString(teamdate.getSecondSectionScore().toString(), 383, 84);
        graphics.drawString(teamdate.getThirdSectionScore().toString(), 407, 84);
        graphics.drawString(teamdate.getFourthSectionScore().toString(), 429, 84);
        graphics.drawString(teamdate.getTotalScore().toString(), 459, 84);
        graphics.drawString(teamdate.getOpponentFirstSectionScore().toString(), 362, 97);
        graphics.drawString(teamdate.getOpponentSecondSectionScore().toString(), 383, 97);
        graphics.drawString(teamdate.getOpponentThirdSectionScore().toString(), 407, 97);
        graphics.drawString(teamdate.getOpponentFourthSectionScore().toString(), 429, 97);
        graphics.drawString(teamdate.getOpponentTotalScore().toString(), 459, 97);
        graphics.setFont(new Font("方正黑体", Font.BOLD, 12));
        graphics.drawString(teamdate.getTeamName(), 140, 80);
        graphics.drawString(teamdate.getOpponentName(), 612, 80);
        graphics.setColor(Color.red);
        graphics.drawString("主", 200, 80);
        graphics.drawString("客", 590, 80);
        graphics.setColor(Color.white);
        graphics.setFont(new Font("方正黑体", Font.BOLD, 12));
        // 球员
      
        graphics.drawString(list.size()>0?list.get(0).getPlayerName():"", 88, 150);
        graphics.drawString(list.size()>1?list.get(1).getPlayerName():"", 88, 170);
        graphics.drawString(list.size()>2?list.get(2).getPlayerName():"", 88, 190);
        graphics.drawString(list.size()>3?list.get(3).getPlayerName():"", 88, 210);
        graphics.drawString(list.size()>4?list.get(4).getPlayerName():"", 88, 230);
        graphics.drawString(list.size()>5?list.get(5).getPlayerName():"", 88, 250);
        graphics.drawString(list.size()>6?list.get(6).getPlayerName():"", 88, 270);
        graphics.drawString(list.size()>7?list.get(7).getPlayerName():"", 88, 290);
        graphics.drawString(list.size()>8?list.get(8).getPlayerName():"", 88, 310);
        graphics.drawString(list.size()>9?list.get(9).getPlayerName():"", 88, 332);
        graphics.drawString(list.size()>10?list.get(10).getPlayerName():"", 88, 352);
        graphics.drawString(list.size()>11?list.get(11).getPlayerName():"", 88,372);
        graphics.drawString(list.size()>12?list.get(12).getPlayerName():"", 88, 392);
        graphics.drawString(list.size()>13?list.get(13).getPlayerName():"", 88, 412);
        graphics.drawString(list.size()>14?list.get(14).getPlayerName():"", 88, 434);
        // 背号
        graphics.drawString(list.size()>0?list.get(0).getPlayerNo():"", 160, 150);
        graphics.drawString(list.size()>1?list.get(1).getPlayerNo():"", 160, 172);
        graphics.drawString(list.size()>2?list.get(2).getPlayerNo():"", 160, 194);
        graphics.drawString(list.size()>3?list.get(3).getPlayerNo():"", 160, 213);
        graphics.drawString(list.size()>4?list.get(4).getPlayerNo():"", 160, 235);
        graphics.drawString(list.size()>5?list.get(5).getPlayerNo():"", 160, 253);
        graphics.drawString(list.size()>6?list.get(6).getPlayerNo():"", 160, 275);
        graphics.drawString(list.size()>7?list.get(7).getPlayerNo():"", 160, 293);
        graphics.drawString(list.size()>8?list.get(8).getPlayerNo():"", 160, 315);
        graphics.drawString(list.size()>9?list.get(9).getPlayerNo():"", 160, 332);
        graphics.drawString(list.size()>10?list.get(10).getPlayerNo():"", 160, 352);
        graphics.drawString(list.size()>11?list.get(11).getPlayerNo():"", 160, 372);
        graphics.drawString(list.size()>12?list.get(12).getPlayerNo():"", 160, 392);
        graphics.drawString(list.size()>13?list.get(13).getPlayerNo():"", 160, 412);
        graphics.drawString(list.size()>14?list.get(14).getPlayerNo():"", 160, 434);
        // 时间
        graphics.drawString(list.size()>0?list.get(0).getPlayingTime()+"":"", 229, 150);
        graphics.drawString(list.size()>1?list.get(1).getPlayingTime()+"":"", 229, 172);
        graphics.drawString(list.size()>2?list.get(2).getPlayingTime()+"":"", 229, 194);
        graphics.drawString(list.size()>3?list.get(3).getPlayingTime()+"":"", 229, 213);
        graphics.drawString(list.size()>4?list.get(4).getPlayingTime()+"":"", 229, 235);
        graphics.drawString(list.size()>5?list.get(5).getPlayingTime()+"":"", 229, 253);
        graphics.drawString(list.size()>6?list.get(6).getPlayingTime()+"":"", 229, 275);
        graphics.drawString(list.size()>7?list.get(7).getPlayingTime()+"":"", 229, 293);
        graphics.drawString(list.size()>8?list.get(8).getPlayingTime()+"":"", 229, 315);
        graphics.drawString(list.size()>9?list.get(9).getPlayingTime()+"":"", 229, 332);
        graphics.drawString(list.size()>10?list.get(10).getPlayingTime()+"":"", 229, 352);
        graphics.drawString(list.size()>11?list.get(11).getPlayingTime()+"":"", 229, 372);
        graphics.drawString(list.size()>12?list.get(12).getPlayingTime()+"":"", 229, 392);
        graphics.drawString(list.size()>13?list.get(13).getPlayingTime()+"":"", 229, 412);
        graphics.drawString(list.size()>14?list.get(14).getPlayingTime()+"":"", 229, 434);
        // 得分
        graphics.drawString(list.size()>0?list.get(0).getTotalScore()+"":"", 296, 150);
        graphics.drawString(list.size()>1?list.get(1).getTotalScore()+"":"", 296, 172);
        graphics.drawString(list.size()>2?list.get(2).getTotalScore()+"":"", 296, 194);
        graphics.drawString(list.size()>3?list.get(3).getTotalScore()+"":"", 296, 213);
        graphics.drawString(list.size()>4?list.get(4).getTotalScore()+"":"", 296, 235);
        graphics.drawString(list.size()>5?list.get(5).getTotalScore()+"":"", 296, 253);
        graphics.drawString(list.size()>6?list.get(6).getTotalScore()+"":"", 296, 275);
        graphics.drawString(list.size()>7?list.get(7).getTotalScore()+"":"", 296, 293);
        graphics.drawString(list.size()>8?list.get(8).getTotalScore()+"":"", 296, 315);
        graphics.drawString(list.size()>9?list.get(9).getTotalScore()+"":"", 296, 332);
        graphics.drawString(list.size()>10?list.get(10).getTotalScore()+"":"", 296, 352);
        graphics.drawString(list.size()>11?list.get(11).getTotalScore()+"":"", 296, 372);
        graphics.drawString(list.size()>12?list.get(12).getTotalScore()+"":"", 296, 492);
        graphics.drawString(list.size()>13?list.get(13).getTotalScore()+"":"", 296, 412);
        graphics.drawString(list.size()>14?list.get(14).getTotalScore()+"":"", 296, 434);
        // 篮板
        graphics.drawString(list.size()>0?list.get(0).getBackboard()+"":"", 360, 150);
        graphics.drawString(list.size()>1?list.get(1).getBackboard()+"":"", 360, 172);
        graphics.drawString(list.size()>2?list.get(2).getBackboard()+"":"", 360, 194);
        graphics.drawString(list.size()>3?list.get(3).getBackboard()+"":"", 360, 213);
        graphics.drawString(list.size()>4?list.get(4).getBackboard()+"":"", 360, 235);
        graphics.drawString(list.size()>5?list.get(5).getBackboard()+"":"", 360, 253);
        graphics.drawString(list.size()>6?list.get(6).getBackboard()+"":"", 360, 275);
        graphics.drawString(list.size()>7?list.get(7).getBackboard()+"":"", 360, 293);
        graphics.drawString(list.size()>8?list.get(8).getBackboard()+"":"", 360, 315);
        graphics.drawString(list.size()>9?list.get(9).getBackboard()+"":"", 360, 332);
        graphics.drawString(list.size()>10?list.get(10).getBackboard()+"":"", 360, 352);
        graphics.drawString(list.size()>11?list.get(11).getBackboard()+"":"", 360, 372);
        graphics.drawString(list.size()>12?list.get(12).getBackboard()+"":"", 360, 492);
        graphics.drawString(list.size()>13?list.get(13).getBackboard()+"":"", 360, 412);
        graphics.drawString(list.size()>14?list.get(14).getBackboard()+"":"", 360, 434);
        // 助攻
        graphics.drawString(list.size()>0?list.get(0).getAssistsAsts()+"":"", 428, 150);
        graphics.drawString(list.size()>1?list.get(1).getAssistsAsts()+"":"", 428, 172);
        graphics.drawString(list.size()>2?list.get(2).getAssistsAsts()+"":"", 428, 194);
        graphics.drawString(list.size()>3?list.get(3).getAssistsAsts()+"":"", 428, 213);
        graphics.drawString(list.size()>4?list.get(4).getAssistsAsts()+"":"", 428, 235);
        graphics.drawString(list.size()>5?list.get(5).getAssistsAsts()+"":"", 428, 253);
        graphics.drawString(list.size()>6?list.get(6).getAssistsAsts()+"":"", 428, 275);
        graphics.drawString(list.size()>7?list.get(7).getAssistsAsts()+"":"", 428, 293);
        graphics.drawString(list.size()>8?list.get(8).getAssistsAsts()+"":"", 428, 315);
        graphics.drawString(list.size()>9?list.get(9).getAssistsAsts()+"":"", 428, 332);
        graphics.drawString(list.size()>10?list.get(10).getAssistsAsts()+"":"", 428, 352);
        graphics.drawString(list.size()>11?list.get(11).getAssistsAsts()+"":"", 428, 372);
        graphics.drawString(list.size()>12?list.get(12).getAssistsAsts()+"":"", 428, 392);
        graphics.drawString(list.size()>13?list.get(13).getAssistsAsts()+"":"", 428, 412);
        graphics.drawString(list.size()>14?list.get(14).getAssistsAsts()+"":"", 428, 434);
        // 抢断
        graphics.drawString(list.size()>0?list.get(0).getSteals()+"":"", 493, 150);
        graphics.drawString(list.size()>1?list.get(1).getSteals()+"":"", 493, 172);
        graphics.drawString(list.size()>2?list.get(2).getSteals()+"":"", 493, 194);
        graphics.drawString(list.size()>3?list.get(3).getSteals()+"":"", 493, 213);
        graphics.drawString(list.size()>4?list.get(4).getSteals()+"":"", 493, 235);
        graphics.drawString(list.size()>5?list.get(5).getSteals()+"":"", 493, 253);
        graphics.drawString(list.size()>6?list.get(6).getSteals()+"":"", 493, 275);
        graphics.drawString(list.size()>7?list.get(7).getSteals()+"":"", 493, 293);
        graphics.drawString(list.size()>8?list.get(8).getSteals()+"":"", 493, 315);
        graphics.drawString(list.size()>9?list.get(9).getSteals()+"":"", 493, 332);
        graphics.drawString(list.size()>10?list.get(10).getSteals()+"":"", 493, 352);
        graphics.drawString(list.size()>11?list.get(11).getSteals()+"":"", 493, 372);
        graphics.drawString(list.size()>12?list.get(12).getSteals()+"":"", 493, 392);
        graphics.drawString(list.size()>13?list.get(13).getSteals()+"":"", 493, 412);
        graphics.drawString(list.size()>14?list.get(14).getSteals()+"":"", 493, 434);
        // 盖帽
      
		
        graphics.drawString(list.size()>0?list.get(0).getCapping()+"":"", 558, 150);
        graphics.drawString(list.size()>1?list.get(1).getCapping()+"":"", 558, 172);
        graphics.drawString(list.size()>2?list.get(2).getCapping()+"":"", 558, 194);
        graphics.drawString(list.size()>3?list.get(3).getCapping()+"":"", 558, 213);
        graphics.drawString(list.size()>4?list.get(4).getCapping()+"":"", 558, 235);
        graphics.drawString(list.size()>5?list.get(5).getCapping()+"":"", 558, 253);
        graphics.drawString(list.size()>6?list.get(6).getCapping()+"":"", 558, 275);
        graphics.drawString(list.size()>7?list.get(7).getCapping()+"":"", 558, 293);
        graphics.drawString(list.size()>8?list.get(8).getCapping()+"":"", 558, 315);
        graphics.drawString(list.size()>9?list.get(9).getCapping()+"":"", 558, 332);
        graphics.drawString(list.size()>10?list.get(10).getCapping()+"":"", 558, 352);
        graphics.drawString(list.size()>11?list.get(11).getCapping()+"":"", 558, 372);
        graphics.drawString(list.size()>12?list.get(12).getCapping()+"":"", 558, 392);
        graphics.drawString(list.size()>13?list.get(13).getCapping()+"":"", 558, 412);
        graphics.drawString(list.size()>14?list.get(14).getCapping()+"":"", 558, 434);
        
        // 失误
        graphics.drawString(list.size()>0?list.get(0).getFault()+"":"", 626, 150);
        graphics.drawString(list.size()>1?list.get(1).getFault()+"":"", 626, 172);
        graphics.drawString(list.size()>2?list.get(2).getFault()+"":"", 626, 194);
        graphics.drawString(list.size()>3?list.get(3).getFault()+"":"", 626, 213);
        graphics.drawString(list.size()>4?list.get(4).getFault()+"":"", 626, 235);
        graphics.drawString(list.size()>5?list.get(5).getFault()+"":"", 626, 253);
        graphics.drawString(list.size()>6?list.get(6).getFault()+"":"", 626, 275);
        graphics.drawString(list.size()>7?list.get(7).getFault()+"":"", 626, 293);
        graphics.drawString(list.size()>8?list.get(8).getFault()+"":"", 626, 315);
        graphics.drawString(list.size()>9?list.get(9).getFault()+"":"", 626, 332);
        graphics.drawString(list.size()>10?list.get(10).getFault()+"":"", 626, 352);
        graphics.drawString(list.size()>11?list.get(11).getFault()+"":"", 626, 372);
        graphics.drawString(list.size()>12?list.get(12).getFault()+"":"", 626, 392);
        graphics.drawString(list.size()>13?list.get(13).getFault()+"":"", 626, 412);
        graphics.drawString(list.size()>14?list.get(14).getFault()+"":"", 626, 434);
        // 犯规
        graphics.drawString(list.size()>0?list.get(0).getFoul()+"":"", 690, 150);
        graphics.drawString(list.size()>1?list.get(1).getFoul()+"":"", 690, 172);
        graphics.drawString(list.size()>2?list.get(2).getFoul()+"":"", 690, 194);
        graphics.drawString(list.size()>3?list.get(3).getFoul()+"":"", 690, 213);
        graphics.drawString(list.size()>4?list.get(4).getFoul()+"":"", 690, 235);
        graphics.drawString(list.size()>5?list.get(5).getFoul()+"":"", 690, 253);
        graphics.drawString(list.size()>6?list.get(6).getFoul()+"":"", 690, 275);
        graphics.drawString(list.size()>7?list.get(7).getFoul()+"":"", 690, 293);
        graphics.drawString(list.size()>8?list.get(8).getFoul()+"":"", 690, 315);
        graphics.drawString(list.size()>9?list.get(9).getFoul()+"":"", 690, 332);
        graphics.drawString(list.size()>10?list.get(10).getFoul()+"":"", 690, 352);
        graphics.drawString(list.size()>11?list.get(11).getFoul()+"":"", 690, 372);
        graphics.drawString(list.size()>12?list.get(12).getFoul()+"":"", 690, 392);
        graphics.drawString(list.size()>13?list.get(13).getFoul()+"":"", 690, 412);
        graphics.drawString(list.size()>14?list.get(14).getFoul()+"":"", 690, 434);
        graphics.setPaintMode();
        graphics.translate(400, 600);
        // 释放此图形的上下文并释放它所使用的所有系统资源
        graphics.dispose();

        try {
            File file = new File(imagefilename);
            ImageIO.write(image, "png", file);
            InputStream is = new FileInputStream(file);
            return is;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

    }
    public static java.util.List<InputStream> create(){
    	return new ArrayList<InputStream>();
    }
    public static <T> InputStream BuildTeam(String background,TeamCreateImg teamdate) throws IOException {
    	Date date=new Date();
    	//生成图片名称
		String imagefilename;
		SimpleDateFormat formatter=new SimpleDateFormat("yyyyHHddHHmmss");  
		String time=formatter.format(date);
		String imagefilesname="/data/tomcat-file/file/webapps/imagess/";
		File files =new File(imagefilesname);    
		//如果文件夹不存在则创建    
		if(!files.exists()&&!files.isDirectory())      
		{       
			files.mkdir();
			imagefilename=imagefilesname+"/"+time+".png";
			File file=new File(imagefilename); 
			//如果文件不存在则创建
				if(!file.exists())    
				{    
					try {    
							file.createNewFile();    
						} catch (IOException e) {    
							e.printStackTrace();    
						}    
				} 
		} else   
		{ 
			 imagefilename=imagefilesname+"/"+time+".png";
			File file=new File(imagefilename); 
			//如果文件不存在则创建
				if(!file.exists())    
				{    
					try {    
							file.createNewFile();    
						} catch (IOException e) {    
							e.printStackTrace();    
						}    
				} 
         
		}  
        // 创建绘制图片
        BufferedImage image;
        // 获得绘制图片url
        URL url = new URL(background);
        // 打开URL对应的资源的输入流
        InputStream backgroundurl = url.openStream();
        // 从网络中读取图片
        image = ImageIO.read(backgroundurl);
        // 获得绘制图片中的左球队队标
        
        String logurl=teamdate.getLogUrl();
        String cu="http://images.cu-league.com";
        String imagelefturl = cu+logurl.replaceFirst("%s","ori");
        
        URL urlleft = new URL(imagelefturl);
        // 获得左球队投篮分布点图片
        String imagelefturlfenbu1=teamdate.getOpponentFullTimeUrl();
        String imagelefturlfenbu = cu+imagelefturlfenbu1.replaceFirst("%s","ori");
        URL urlleftfenbu = new URL(imagelefturlfenbu);
        // 打开URL对应的资源的输入流
        
        InputStream imageleft = urlleft.openStream();
        InputStream imageleftfenbu = urlleftfenbu.openStream();
        // 从网络中添加图片
        BufferedImage bufferedImageLeft = ImageIO.read(imageleft);
        BufferedImage bufferedImageLeftfenbu = ImageIO.read(imageleftfenbu);

        // BufferedImage bufferedImagerightfenbu = ImageIO.read(new
        // File("C:/Users/XT00001/Desktop/B图.jpg"));
        // 获得绘制图片中的右球队队标
        String imagerighturlfenbu1=teamdate.getLogUrl();
        String imagerighturlfenbu = cu+imagerighturlfenbu1.replaceFirst("%s","ori");
        URL urlright = new URL(imagelefturl);
        URL urlrightfenbu = new URL(imagerighturlfenbu);
        // BufferedImage bufferedImageright = ImageIO.read(new
        // File("C:/Users/XT00001/Desktop/jiaotong (2) - 副本.png"));
        // 打开URL对应的资源的输入流
        InputStream imageright = urlright.openStream();
        InputStream imagerightfenbu = urlrightfenbu.openStream();
        // 从网络中添加图片
        BufferedImage bufferedImageright = ImageIO.read(imageright);
        BufferedImage bufferedImagerightfenbu = ImageIO.read(imagerightfenbu);

        // image = ImageIO.read(new File("C:/Users/XT00001/Desktop/11-01.png"));
     

        // 获取图形上下文
        Graphics2D graphics = (Graphics2D) image.getGraphics();


        graphics.drawImage(bufferedImageLeft, 80, 130, 100, 100, null);
        graphics.drawImage(bufferedImageright, 620, 130, 100, 100, null);
        graphics.drawImage(bufferedImageLeftfenbu, 35, 320, 200, 120, null);
        graphics.drawImage(bufferedImagerightfenbu, 570, 320, 200, 120, null);

        // 消除线条锯齿
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        RenderingHints rh = new RenderingHints(
                RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        rh.put(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        graphics.setRenderingHints(rh); // 设置图片质量

        graphics.setStroke(new BasicStroke(3)); // 设置线的粗细
        // 标题
        String text = "2014-2015 U-LEAGUE";
        Font font = new Font("方正超粗黑", Font.LAYOUT_RIGHT_TO_LEFT, 18);
        FontRenderContext frc1 = graphics.getFontRenderContext();
        TextLayout tl1 = new TextLayout(text, font, frc1);
        tl1.draw(graphics, 307, 35);
        graphics.setColor(Color.white);

        // 获取球队名称
        graphics.setFont(new Font("方正黑体", Font.BOLD, 18));
        graphics.drawString(teamdate.getTeamName()==null?"":teamdate.getTeamName()+"", 80, 83);
        graphics.drawString(teamdate.getOpponentName()==null?"":teamdate.getOpponentName()+"", 630, 83);



        // 设置文字内容、位置
        graphics.setFont(new Font("方正黑体", Font.BOLD, 30));

        graphics.drawString(teamdate.getTotalScore()==null?"":teamdate.getTotalScore()+"", 345, 98);
        graphics.drawString(teamdate.getOpponentTotalScore()==null?"":teamdate.getOpponentTotalScore()+"", 425, 98);



        graphics.setFont(new Font("方正黑体", Font.BOLD, 15));
      

        // A队数据
        
        //投篮次数
        graphics.drawString(teamdate.getShootBasketTotal()==null?"":teamdate.getShootBasketTotal()+"", 296, 150);
       //命中率
        String TotalHit;
        String Total;
    	if(teamdate.getTotalHit().toString()==null){
    		TotalHit=" ";
    		Total=TotalHit;
    	}else {
    		TotalHit=teamdate.getFreeThrowHitRate().toString();
    		if(TotalHit.length()>=3){
    			Total=TotalHit.substring(0, 3);
    		}else {
    			Total=TotalHit;
			}
		}
        graphics.drawString(Total, 296, 172);
        //两分球
        graphics.drawString(teamdate.getTwoPointsHitTotal()==null?"":teamdate.getTwoPointsHitTotal()+"", 296, 194);
        String twopointshitrate;
        String s2;
    	if(teamdate.getThreePointsHitRate().toString()==null){
    		 twopointshitrate=" ";
    		 s2=twopointshitrate;
    	}else {
    		twopointshitrate=teamdate.getThreePointsHitRate().toString();
    		if(twopointshitrate.length()>=3){
    			s2=twopointshitrate.substring(0, 3);
    		}else {
    			s2=twopointshitrate;
			}
		}
        //两分球命中率
        graphics.drawString(s2, 296, 213);
        //三分球
        graphics.drawString(teamdate.getThreePointsHitTotal()==null?"":teamdate.getThreePointsHitTotal()+"", 296, 235);
        String threepointshitrate;
    	String s3;
    	if(teamdate.getThreePointsHitRate().toString()==null){
    		 threepointshitrate=" ";
    		 s3=threepointshitrate;
    	}else {
    		threepointshitrate=teamdate.getThreePointsHitRate().toString();
    		if(threepointshitrate.length()>=3){
    			s3=threepointshitrate.substring(0, 3);
    		}else {
    			s3=threepointshitrate;
			}
		}
    	//三分球命中率
        graphics.drawString(s3, 296, 253);
        //罚球
        graphics.drawString(teamdate.getFreeThrowTotal()==null?"":teamdate.getFreeThrowTotal()+"", 296, 275);
        //罚篮命中率
        String FreeThrowHitRate;
        String FreeThrow;
    	if(teamdate.getFreeThrowHitRate().toString()==null){
    		FreeThrowHitRate=" ";
    		FreeThrow=FreeThrowHitRate;
    	}else {
    		FreeThrowHitRate=teamdate.getFreeThrowHitRate().toString();
    		if(FreeThrowHitRate.length()>=3){
    			FreeThrow=FreeThrowHitRate.substring(0, 3);
    		}else {
    			FreeThrow=FreeThrowHitRate;
			}
		}
        graphics.drawString(FreeThrow, 296, 293);
        //助攻次数
        graphics.drawString(teamdate.getAssistsAsts()==null?"":teamdate.getAssistsAsts()+"", 296, 317);
        //前场
        graphics.drawString(teamdate.getFreeThrowHitRate()==null?"":teamdate.getFrontBackboard()+"", 296,335);
        //后场篮板
        graphics.drawString(teamdate.getBackBackboard()==null?"":teamdate.getBackBackboard()+"", 296, 360);
        //总篮板
        graphics.drawString(teamdate.getBackboard()==null?"":teamdate.getBackboard()+"", 296, 383);
      
        //封盖
        graphics.drawString(teamdate.getCapping()==null?"":teamdate.getCapping()+"", 296, 405);
        //抢断
        graphics.drawString(teamdate.getSteals()==null?"":teamdate.getSteals()+"", 296, 427);
        //失误
        graphics.drawString(teamdate.getFault()==null?"":teamdate.getFault()+"", 296, 449);
        //犯规
        graphics.drawString(teamdate.getFoul()==null?"":teamdate.getFoul()+"", 296, 471);

        // 数据
    	graphics.drawString("投篮次数", 370, 150);
        graphics.drawString("命中率", 380, 172);
        graphics.drawString("2分球", 383, 194);
        graphics.drawString("2分球命中率%", 360, 213);
        graphics.drawString("3分球", 383, 235);
        graphics.drawString("3分球命中率%", 360, 253);
        
        graphics.drawString("罚篮", 388, 275);
        
        graphics.drawString("罚篮命中率", 365, 293);
        graphics.drawString("助攻次数", 370, 315);
        graphics.drawString("前场", 388, 335);
        
        graphics.drawString("后场", 388, 360);
        graphics.drawString("总篮板", 380, 380);
        
        graphics.drawString("封盖", 390, 405);
        graphics.drawString("抢断", 390, 427);
        graphics.drawString("失误", 390, 449);
        graphics.drawString("犯规", 390, 471);
        // B队数据
      //投篮次数
        graphics.drawString(teamdate.getOpponentShootBasketTotal()==null?"":teamdate.getOpponentShootBasketTotal()+"", 495, 150);
        //总命中率
        String OpponentTotalHit;
        String OpponentTotal;
    	if(teamdate.getOpponentTotalHit().toString()==null){
    		OpponentTotalHit=" ";
    		OpponentTotal=OpponentTotalHit;
    	}else {
    		OpponentTotalHit=teamdate.getOpponentTotalHit().toString();
    		if(OpponentTotalHit.length()>=3){
    			OpponentTotal=OpponentTotalHit.substring(0, 3);
    		}else {
    			OpponentTotal=OpponentTotalHit;
			}
		}
        graphics.drawString(OpponentTotal, 493, 172);
        //两分球
        graphics.drawString(teamdate.getOpponentTwoPointsHitTotal()==null?"":teamdate.getOpponentTwoPointsHitTotal()+"", 493, 194);
        //两分球命中率
        String twopointshitrate1;
        String s21;
    	if(teamdate.getThreePointsHitRate().toString()==null){
    		 twopointshitrate1=" ";
    		 s21=twopointshitrate;
    	}else {
    		twopointshitrate1=teamdate.getThreePointsHitRate().toString();
    		if(twopointshitrate1.length()>=3){
    			s21=twopointshitrate1.substring(0, 3);
    		}else {
    			s21=twopointshitrate1;
			}
		}
        graphics.drawString(s21, 493, 213);
        //三分球
        graphics.drawString(teamdate.getOpponentThreePointsHitTotal()==null?"":teamdate.getOpponentThreePointsHitTotal()+"", 493, 235);
        //三分球命中率
        String threepointshitrate1;
        String s31;
    	if(teamdate.getThreePointsHitRate().toString()==null){
    		threepointshitrate1=" ";
    		s31=threepointshitrate1;
    	}else {
    		
    		threepointshitrate1=teamdate.getThreePointsHitRate().toString();
    		if(threepointshitrate1.length()>=3){
    			s31=threepointshitrate1.substring(0, 3);
    		}else {
    			s31=threepointshitrate1;
			}
    		 
		}
        graphics.drawString(s31, 493, 253);
        //罚球
        graphics.drawString(teamdate.getOpponentFreeThrowTotal()==null?"":teamdate.getOpponentFreeThrowTotal()+"", 493, 275);
        //罚篮命中率
        String OpponentFreeThrowHitRate;
        String OpponentFreeThrow;
    	if(teamdate.getOpponentFreeThrowHitRate().toString()==null){
    		OpponentFreeThrowHitRate=" ";
    		OpponentFreeThrow=OpponentFreeThrowHitRate;
    	}else {
    		OpponentFreeThrowHitRate=teamdate.getOpponentFreeThrowHitRate().toString();
    		if(OpponentTotalHit.length()>=3){
    			OpponentFreeThrow=OpponentFreeThrowHitRate.substring(0, 3);
    		}else {
    			OpponentFreeThrow=OpponentFreeThrowHitRate;
			}
		}
        graphics.drawString(OpponentFreeThrow, 493, 293);
        //助攻次数
        graphics.drawString(teamdate.getOpponentAssistsAsts()==null?"":teamdate.getOpponentAssistsAsts()+"", 493, 317);
        //前场
        graphics.drawString(teamdate.getOpponentFrontBackboard()==null?"":teamdate.getOpponentFrontBackboard()+"", 493,335);
        //后场篮板
        graphics.drawString(teamdate.getOpponentBackBackboard()==null?"":teamdate.getOpponentBackBackboard()+"", 493, 360);
        //总篮板
        graphics.drawString(teamdate.getOpponentBackboard()==null?"":teamdate.getOpponentBackboard()+"", 493, 383);
      
        //封盖
        graphics.drawString(teamdate.getOpponentCapping()==null?"":teamdate.getOpponentCapping()+"", 493, 405);
        //抢断
        graphics.drawString(teamdate.getOpponentSteals()==null?"":teamdate.getOpponentSteals()+"", 493, 427);
        //失误
        graphics.drawString(teamdate.getOpponentFault()==null?"":teamdate.getOpponentFault()+"", 493, 449);
        //犯规
        graphics.drawString(teamdate.getOpponentFoul()==null?"":teamdate.getOpponentFoul()+"", 493, 471);
       
        graphics.setPaintMode();
        graphics.translate(400, 600);
        // 释放此图形的上下文并释放它所使用的所有系统资源
        graphics.dispose();

        try {

            
            File file = new File(imagefilesname);
            ImageIO.write(image, "png", file);
            InputStream is = new FileInputStream(file);
            return is;
        } catch (IOException e) {
            e.printStackTrace();
        }
		return null;

    }
    public static List stream(TeamCreateImg teamdate){
    	//TeamCreateImg teamdate=new TeamCreateImg();
    	List<InputStream> arraylist=new ArrayList<InputStream>();
    	try {
			InputStream inputsteamteam=imageUtil.BuildTeam("http://imgdata.hoop8.com/1410/0781960981939.png", teamdate);
			InputStream inputsteamplayer=imageUtil.BuildPlayer("http://www.mftp.info/20141001/1413706643x460551387.png",teamdate);
			
			arraylist.add(inputsteamteam);
			arraylist.add(inputsteamplayer);
			 
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
		return arraylist;
		}
}
